import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'limitThroughReportM',
  state: {},
  effects: {
    // 获取列表数据
    *getTableData({ payload, callback }, { call, put }) {
      const response = yield call(api.limitThroughReport.queryReportTable, payload);
      if (response && response.code == 0) {
        const columns = [
          {
            dataIndex: 'ruleNo',
            title: '风险编号',
            key: 'ruleNo',
          },
          {
            dataIndex: 'ruleDesc',
            title: '风险说明',
            key: 'ruleDesc',
          },
          {
            dataIndex: 'value',
            title: '指标值',
            key: 'value',
          },
          {
            dataIndex: 'warningValue',
            title: '触警值',
            key: 'warningValue',
          },
          {
            dataIndex: 'prohibitValue',
            title: '禁止值',
            key: 'prohibitValue',
          },
          {
            dataIndex: 'marginValue',
            title: '剩余值',
            key: 'marginValue',
          },
        ];
        callback('success', {
          columns,
          ...response.data,
        });
      } else {
        callback('fail');
        message.error(response?.msg || '查询失败！');
      }
    },
    // 获取T-1交易日
    *getPreviewDay({ payload, callback }, { call, put }) {
      const response = yield call(api.limitThroughReport.previousTradingDay, payload);
      if (response && response.code == 0) {
        callback('success', response.data);
      } else {
        callback('fail');
        message.error(response?.msg || '获取T-1交易日失败！');
      }
    },
    //获取数据日志列表
    *queryLogList({ payload, callback }, { call, put }) {
      const response = yield call(api.limitThroughReport.queryLogList, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg || '查询失败！');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
